package com.sfc.sdsr.activity;

import java.util.List;
import com.sfc.sdsr.R;
import com.sfc.sdsr.common.model.Event;
import com.sfc.sdsr.dao.DataToJava;
import com.sfc.sdsr.dao.SqliteDao;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class EventsActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        DataToJava dataToJava = new DataToJava(this, "sfc.db", null, 3);
        SqliteDao sqliteDao = new SqliteDao(this, "sfc.db", null, 3);
        sqliteDao.setDataToJava(dataToJava);
        
        setContentView(R.layout.events);

        List<Event> events = sqliteDao.getEvents();

        // -------------------------------- Setting up the table ------------------------------------------ //
        TableRow.LayoutParams tableRowLayoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT);
        TableLayout.LayoutParams tableLayoutLayoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);

        TableLayout tableLayout = (TableLayout) findViewById(R.id.eventsTable);

        for (Event currentEvent : events) {
            TextView textView = new TextView(this);
            textView.setText(currentEvent.toString());
            textView.setTextColor(Color.WHITE);
            textView.setBackgroundColor(Color.DKGRAY);

            TableRow tableRow = new TableRow(this);
            tableRow.setLayoutParams(tableRowLayoutParams);
            tableRow.setBackgroundColor(Color.GREEN);
            tableRow.addView(textView);

            tableLayout.addView(tableRow, tableLayoutLayoutParams);
        }
        // ------------------------------------------------------------------------------------------------ //

    }

}
